/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.generatepage.web.MainGoldAdvAction
   Module Description   :

   Date Created      : 2010/1/8
   Original Author   : feeling.wang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.generatepage.web;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.imageio.ImageIO;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.utils.DateUtil;
import com.yaodian100.ec.category.entity.Category;
import com.yaodian100.ec.category.service.CategoryService;
import com.yaodian100.ec.common.EcConstant;
import com.yaodian100.ec.generate.entity.EventImage;
import com.yaodian100.ec.generate.entity.GenerateAdvertise;
import com.yaodian100.ec.generate.entity.GenerateContent;
import com.yaodian100.ec.generate.entity.GeneratePosition;
import com.yaodian100.ec.generate.service.GenerateService;

/**
 * @author feeling.wang
 * 
 */
public class MainGoldAdvAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -779585337876728623L;
	/** logger */
	private final Logger logger = LoggerFactory.getLogger(MainGoldAdvAction.class);
	private GenerateService generateService;
	private CategoryService categoryService;
	private GenerateAdvertise advertise;
	private GeneratePosition position;
	private GenerateContent content;
	private List<Category> categoryRoot;
	private StringBuilder contents = null;
	private EventImage eventImage = null;
	private String advId;
	private String advStatus;// 00:草稿,10:发送,90:取消
	private String advName;
	private String startDate;// 开始时间
	private String endDate;// 结束时间
	private String mainCateId;
	private String childCateId;
	private String advType;
	private String startTime;
	private String endTime;
	private String from;
	private Date createDate;
	private String createUser;
	private Date modifyDate;
	private String modifyUser;

	/* category parameters */
	private String tab1Title;
	private String tab1LayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File tab1MainImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String tab1ImgFolder;
	private String tab1MainImgName;
	private String tab1MainImgLink;

	private String tab1MainPromotion;
	private String tab1SecondPromotion;
	private String tab1ProdId1;
	private String tab1ProdId2;

	private String tab2Title;
	private String tab2LayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File tab2MainImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String tab2ImgFolder;
	private String tab2MainImgName;
	private String tab2MainImgLink;

	private String tab2MainPromotion;
	private String tab2SecondPromotion;
	private String tab2ProdId1;
	private String tab2ProdId2;

	private String tab3Title;
	private String tab3LayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File tab3MainImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String tab3ImgFolder;
	private String tab3MainImgName;
	private String tab3MainImgLink;

	private String tab3MainPromotion;
	private String tab3SecondPromotion;
	private String tab3ProdId1;
	private String tab3ProdId2;

	private String tab4Title;
	private String tab4LayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File tab4MainImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String tab4ImgFolder;
	private String tab4MainImgName;
	private String tab4MainImgLink;

	private String tab4MainPromotion;
	private String tab4SecondPromotion;
	private String tab4ProdId1;
	private String tab4ProdId2;

	private String tab5Title;
	private String tab5LayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File tab5MainImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String tab5ImgFolder;
	private String tab5MainImgName;
	private String tab5MainImgLink;

	private String tab5MainPromotion;
	private String tab5SecondPromotion;
	private String tab5ProdId1;
	private String tab5ProdId2;

	/* index parameter */
	private String idxLayoutType;// IMG:圖、FLASH:flash、IMGTEXT:圖文
	private File idxImg;// 圖文的大圖或上傳單一圖檔及flash共用
	private String idxShowSeq;
	private String idxImgFolder;
	private String idxImgName;
	private String idxImgLink;
	private String adWord;

	/* category index parameter */
	private String cateLayoutType1;
	private File cateSubImg1;
	private File cateMainImg1;
	private String cateSubImgFolder1;
	private String cateMainImgFolder1;
	private String cateSubImgName1;
	private String cateMainImgName1;
	private String cateImgLink1;
	private String cateLayoutType2;
	private File cateSubImg2;
	private File cateMainImg2;
	private String cateSubImgFolder2;
	private String cateMainImgFolder2;
	private String cateSubImgName2;
	private String cateMainImgName2;
	private String cateImgLink2;
	private String cateLayoutType3;
	private File cateSubImg3;
	private File cateMainImg3;
	private String cateSubImgFolder3;
	private String cateMainImgFolder3;
	private String cateSubImgName3;
	private String cateMainImgName3;
	private String cateImgLink3;
	private String cateLayoutType4;
	private File cateSubImg4;
	private File cateMainImg4;
	private String cateSubImgFolder4;
	private String cateMainImgFolder4;
	private String cateSubImgName4;
	private String cateMainImgName4;
	private String cateImgLink4;
	
	private boolean doClone;
	
	private final String lineBreak = "\n";
	private final DateFormat PATTERN_DATE_FORMAT = new SimpleDateFormat(EcConstant.PATTERN_TIMESTAMP);

	/**
	 * 新增馆首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addCateMainGoldAdv() throws Exception {
		initVariables();
		advId = "";
		advType = "000_MAINGOLD_V2";
		return "editCateMainGoldAdv";
	}

	/**
	 * 新增首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addIdxMainGoldAdv() throws Exception {
		initVariables();
		advId = "";
		advType = "IDX_MAINGOLD";
		return "editIdxMainGoldAdv";
	}

	/**
	 * 新增首页大看版广告_V2
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addIdxMainGoldAdv_V2() throws Exception {
		initVariables();
		advId = "";
		if( StringUtils.equalsIgnoreCase(from, "PCL") )
			advType = "PCL_MAINGOLD_V2";
		else
			advType = "IDX_MAINGOLD_V2";
		return "editIdxMainGoldAdv_V2";
	}
	
	/**
	 * 新增Outlets品牌折扣馆厂商Banner
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addOutletsBannerAdv() throws Exception {
		initVariables();
		advId = "";
		advType = "OUTLETS_BANNER";
		return "editOutletsBannerAdv";
	}

	/**
	 * 新增館首頁、第二分類頁大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addMainGoldAdv() throws Exception {
		initVariables();
		advId = "";
		return "editMainGoldAdv";
	}

	/**
	 * 编辑馆首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editCateMainGoldAdv() throws Exception {
		editCommonMainGold();
		return "editCateMainGoldAdv";
	}

	void editCommonMainGold() throws IOException {
		initVariables();
		advertise = generateService.get(Long.parseLong(advId));
		position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
		content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
		advName = advertise.getAdvName();
		advType = advertise.getAdvType();
		startDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getStartDate());
		endDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getEndDate());
		createDate = advertise.getCreateDate();
		createUser = advertise.getCreateUser();
		modifyDate = advertise.getModifyDate();
		modifyUser = advertise.getModifyUser();
		
		if (StringUtils.equalsIgnoreCase("000_MAINGOLD", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
		} else if (StringUtils.equalsIgnoreCase("100_MAINGOLD", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
			childCateId = position.getChildCateId().toString();
		} else if (StringUtils.equalsIgnoreCase("000_MAINGOLD_V2", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
		}
		if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD_V2", advertise.getAdvType()) || StringUtils.equalsIgnoreCase("PCL_MAINGOLD_V2", advertise.getAdvType())) {
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readIdxPropertise(advertise.getAdvType(), content);
		} else if (StringUtils.equalsIgnoreCase("000_MAINGOLD_V2", advertise.getAdvType())) {
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readCatePropertise(advertise.getAdvType(), content);
		} else if (StringUtils.equalsIgnoreCase("OUTLETS_BANNER", advertise.getAdvType())){
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readIdxPropertise(advertise.getAdvType(), content);
		} else {
			readPropertise(advertise.getAdvType(), content);
		}
	}

	/**
	 * 编辑首页/广首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editIdxMainGoldAdv() throws Exception {
		editCommonMainGold();
		return "editIdxMainGoldAdv";
	}

	/**
	 * 编辑首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editIdxMainGoldAdv_V2() throws Exception {
		editCommonMainGold();
		idxShowSeq = String.valueOf(content.getShowSeq());
		return "editIdxMainGoldAdv_V2";
	}

	void cloneCommonMainGold() throws IOException {
		initVariables();
		doClone = true;
		advertise = generateService.get(Long.parseLong(advId));
		position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
		content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
		
		GenerateAdvertise tmp_advertise = new GenerateAdvertise();
		BeanUtils.copyProperties(advertise, tmp_advertise, new String[] {"id", "createDate", "createUser", "modifyUser", "modifyDate"});
		advertise = tmp_advertise;
		
		GeneratePosition tmp_position = new GeneratePosition();
		BeanUtils.copyProperties(position, tmp_position, new String[] {"id", "advId", "createDate", "createUser", "modifyUser", "modifyDate"});
		position = tmp_position;
		
		GenerateContent tmp_content = new GenerateContent();
		BeanUtils.copyProperties(content, tmp_content, new String[] {"id", "advId", "createDate", "createUser", "modifyUser", "modifyDate"});
		content = tmp_content;
		
		advName = advertise.getAdvName();
		advType = advertise.getAdvType();
		startDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getStartDate());
		endDate = FastDateFormat.getInstance(EcConstant.PATTERN_DATE).format(advertise.getEndDate());
		createDate = advertise.getCreateDate();
		createUser = advertise.getCreateUser();
		modifyDate = advertise.getModifyDate();
		modifyUser = advertise.getModifyUser();
		
		if (StringUtils.equalsIgnoreCase("000_MAINGOLD", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
		} else if (StringUtils.equalsIgnoreCase("100_MAINGOLD", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
			childCateId = position.getChildCateId().toString();
		} else if (StringUtils.equalsIgnoreCase("000_MAINGOLD_V2", advertise.getAdvType())) {
			mainCateId = position.getMainCateId().toString();
		}
		if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD_V2", advertise.getAdvType()) || StringUtils.equalsIgnoreCase("PCL_MAINGOLD_V2", advertise.getAdvType())) {
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readIdxPropertise(advertise.getAdvType(), content);
		} else if (StringUtils.equalsIgnoreCase("000_MAINGOLD_V2", advertise.getAdvType())) {
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readCatePropertise(advertise.getAdvType(), content);
		} else if (StringUtils.equalsIgnoreCase("OUTLETS_BANNER", advertise.getAdvType())){
			startTime = FastDateFormat.getInstance("HH:mm").format(advertise.getStartDate());
			endTime = FastDateFormat.getInstance("HH:mm").format(advertise.getEndDate());
			readIdxPropertise(advertise.getAdvType(), content);
		} else {
			readPropertise(advertise.getAdvType(), content);
		}
	}
	
	public String cloneIdxMainGoldAdv_V2() throws Exception {
		cloneCommonMainGold();
		idxShowSeq = String.valueOf(content.getShowSeq());
		advId = null;
		return "editIdxMainGoldAdv_V2";
	}
	
	/**
	 * 编辑Outlets品牌折扣馆厂商Banner
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editOutletsBannerAdv() throws Exception {
		editCommonMainGold();
		idxShowSeq = String.valueOf(content.getShowSeq());
		return "editOutletsBannerAdv";
	}
	
	public String cloneOutletsBannerAdv() throws Exception {
		cloneCommonMainGold();
		idxShowSeq = String.valueOf(content.getShowSeq());
		return "editOutletsBannerAdv";
	}

	/**
	 * 编辑首页/广首页大看版广告
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editMainGoldAdv() throws Exception {
		editCommonMainGold();
		return "editMainGoldAdv";
	}

	public GenerateAdvertise getAdvertise() {
		return advertise;
	}

	public String getAdvId() {
		return advId;
	}

	public String getAdvName() {
		return advName;
	}

	public String getAdvStatus() {
		return advStatus;
	}

	public String getAdvType() {
		return advType;
	}

	public List<Category> getCategoryRoot() {
		return categoryRoot;
	}

	public String getCateImgLink1() {
		return cateImgLink1;
	}

	public String getCateImgLink2() {
		return cateImgLink2;
	}

	public String getCateImgLink3() {
		return cateImgLink3;
	}

	public String getCateImgLink4() {
		return cateImgLink4;
	}

	public String getCateLayoutType1() {
		return cateLayoutType1;
	}

	public String getCateLayoutType2() {
		return cateLayoutType2;
	}

	public String getCateLayoutType3() {
		return cateLayoutType3;
	}

	public String getCateLayoutType4() {
		return cateLayoutType4;
	}

	public File getCateMainImg1() {
		return cateMainImg1;
	}

	public File getCateMainImg2() {
		return cateMainImg2;
	}

	public File getCateMainImg3() {
		return cateMainImg3;
	}

	public File getCateMainImg4() {
		return cateMainImg4;
	}

	public String getCateMainImgFolder1() {
		return cateMainImgFolder1;
	}

	public String getCateMainImgFolder2() {
		return cateMainImgFolder2;
	}

	public String getCateMainImgFolder3() {
		return cateMainImgFolder3;
	}

	public String getCateMainImgFolder4() {
		return cateMainImgFolder4;
	}

	public String getCateMainImgName1() {
		return cateMainImgName1;
	}

	public String getCateMainImgName2() {
		return cateMainImgName2;
	}

	public String getCateMainImgName3() {
		return cateMainImgName3;
	}

	public String getCateMainImgName4() {
		return cateMainImgName4;
	}

	public File getCateSubImg1() {
		return cateSubImg1;
	}

	public File getCateSubImg2() {
		return cateSubImg2;
	}

	public File getCateSubImg3() {
		return cateSubImg3;
	}

	public File getCateSubImg4() {
		return cateSubImg4;
	}

	public String getCateSubImgFolder1() {
		return cateSubImgFolder1;
	}

	public String getCateSubImgFolder2() {
		return cateSubImgFolder2;
	}

	public String getCateSubImgFolder3() {
		return cateSubImgFolder3;
	}

	public String getCateSubImgFolder4() {
		return cateSubImgFolder4;
	}

	public String getCateSubImgName1() {
		return cateSubImgName1;
	}

	public String getCateSubImgName2() {
		return cateSubImgName2;
	}

	public String getCateSubImgName3() {
		return cateSubImgName3;
	}

	public String getCateSubImgName4() {
		return cateSubImgName4;
	}

	public String getChildCateId() {
		return childCateId;
	}

	public GenerateContent getContent() {
		return content;
	}

	public StringBuilder getContents() {
		return contents;
	}

	public String getEndDate() {
		return endDate;
	}

	public String getEndTime() {
		return endTime;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.Preparable#prepare()
	 */

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public String getModifyUser() {
		return modifyUser;
	}

	public void setModifyUser(String modifyUser) {
		this.modifyUser = modifyUser;
	}

	public EventImage getEventImage() {
		return eventImage;
	}

	public File getIdxImg() {
		return idxImg;
	}

	public String getIdxImgFolder() {
		return idxImgFolder;
	}

	public String getIdxImgLink() {
		return idxImgLink;
	}

	public String getIdxImgName() {
		return idxImgName;
	}

	public String getIdxLayoutType() {
		return idxLayoutType;
	}

	public String getIdxShowSeq() {
		return idxShowSeq;
	}

	public String getMainCateId() {
		return mainCateId;
	}

	public GeneratePosition getPosition() {
		return position;
	}

	public String getStartDate() {
		return startDate;
	}

	public String getStartTime() {
		return startTime;
	}

	public String getTab1ImgFolder() {
		return tab1ImgFolder;
	}

	public String getTab1LayoutType() {
		return tab1LayoutType;
	}

	public File getTab1MainImg() {
		return tab1MainImg;
	}

	public String getTab1MainImgLink() {
		return tab1MainImgLink;
	}

	public String getTab1MainImgName() {
		return tab1MainImgName;
	}

	public String getTab1MainPromotion() {
		return tab1MainPromotion;
	}

	public String getTab1ProdId1() {
		return tab1ProdId1;
	}

	public String getTab1ProdId2() {
		return tab1ProdId2;
	}

	public String getTab1SecondPromotion() {
		return tab1SecondPromotion;
	}

	public String getTab1Title() {
		return tab1Title;
	}

	public String getTab2ImgFolder() {
		return tab2ImgFolder;
	}

	public String getTab2LayoutType() {
		return tab2LayoutType;
	}

	public File getTab2MainImg() {
		return tab2MainImg;
	}

	public String getTab2MainImgLink() {
		return tab2MainImgLink;
	}

	public String getTab2MainImgName() {
		return tab2MainImgName;
	}

	public String getTab2MainPromotion() {
		return tab2MainPromotion;
	}

	public String getTab2ProdId1() {
		return tab2ProdId1;
	}

	public String getTab2ProdId2() {
		return tab2ProdId2;
	}

	public String getTab2SecondPromotion() {
		return tab2SecondPromotion;
	}

	public String getTab2Title() {
		return tab2Title;
	}

	public String getTab3ImgFolder() {
		return tab3ImgFolder;
	}

	public String getTab3LayoutType() {
		return tab3LayoutType;
	}

	public File getTab3MainImg() {
		return tab3MainImg;
	}

	public String getTab3MainImgLink() {
		return tab3MainImgLink;
	}

	public String getTab3MainImgName() {
		return tab3MainImgName;
	}

	public String getTab3MainPromotion() {
		return tab3MainPromotion;
	}

	public String getTab3ProdId1() {
		return tab3ProdId1;
	}

	public String getTab3ProdId2() {
		return tab3ProdId2;
	}

	public String getTab3SecondPromotion() {
		return tab3SecondPromotion;
	}

	public String getTab3Title() {
		return tab3Title;
	}

	public String getTab4ImgFolder() {
		return tab4ImgFolder;
	}

	public String getTab4LayoutType() {
		return tab4LayoutType;
	}

	public File getTab4MainImg() {
		return tab4MainImg;
	}

	public String getTab4MainImgLink() {
		return tab4MainImgLink;
	}

	public String getTab4MainImgName() {
		return tab4MainImgName;
	}

	public String getTab4MainPromotion() {
		return tab4MainPromotion;
	}

	public String getTab4ProdId1() {
		return tab4ProdId1;
	}

	public String getTab4ProdId2() {
		return tab4ProdId2;
	}

	public String getTab4SecondPromotion() {
		return tab4SecondPromotion;
	}

	public String getTab4Title() {
		return tab4Title;
	}

	public String getTab5ImgFolder() {
		return tab5ImgFolder;
	}

	public String getTab5LayoutType() {
		return tab5LayoutType;
	}

	public File getTab5MainImg() {
		return tab5MainImg;
	}

	public String getTab5MainImgLink() {
		return tab5MainImgLink;
	}

	public String getTab5MainImgName() {
		return tab5MainImgName;
	}

	public String getTab5MainPromotion() {
		return tab5MainPromotion;
	}

	public String getTab5ProdId1() {
		return tab5ProdId1;
	}

	public String getTab5ProdId2() {
		return tab5ProdId2;
	}

	public String getTab5SecondPromotion() {
		return tab5SecondPromotion;
	}

	public String getTab5Title() {
		return tab5Title;
	}

	/**
	 * 初始化变数值
	 */
	void initVariables() {
		advertise = new GenerateAdvertise();
		position = new GeneratePosition();
		content = new GenerateContent();

		advStatus = "";
		advName = "";
		startDate = "";
		endDate = "";
		createDate = null;
		createUser = "";
		modifyDate = null;
		modifyUser = "";
		mainCateId = "";
		childCateId = "";
		// advType = "";

		tab1LayoutType = "";
		tab1Title = "";
		tab1MainImg = null;
		tab1ImgFolder = "";
		tab1MainImgName = "";
		tab1MainImgLink = "";

		tab1MainPromotion = "";
		tab1SecondPromotion = "";
		tab1ProdId1 = "";
		tab1ProdId2 = "";

		tab2LayoutType = "";
		tab2Title = "";
		tab2MainImg = null;
		tab2ImgFolder = "";
		tab2MainImgName = "";
		tab2MainImgLink = "";

		tab2MainPromotion = "";
		tab2SecondPromotion = "";
		tab2ProdId1 = "";
		tab2ProdId2 = "";

		tab3LayoutType = "";
		tab3Title = "";
		tab3MainImg = null;
		tab3ImgFolder = "";
		tab3MainImgName = "";
		tab3MainImgLink = "";

		tab3MainPromotion = "";
		tab3SecondPromotion = "";
		tab3ProdId1 = "";
		tab3ProdId2 = "";

		tab4LayoutType = "";
		tab4Title = "";
		tab4MainImg = null;
		tab4ImgFolder = "";
		tab4MainImgName = "";
		tab4MainImgLink = "";

		tab4MainPromotion = "";
		tab4SecondPromotion = "";
		tab4ProdId1 = "";
		tab4ProdId2 = "";

		tab5LayoutType = "";
		tab5Title = "";
		tab5MainImg = null;
		tab5ImgFolder = "";
		tab5MainImgName = "";
		tab5MainImgLink = "";

		tab5MainPromotion = "";
		tab5SecondPromotion = "";
		tab5ProdId1 = "";
		tab5ProdId2 = "";

		startDate = "";
		endDate = "";
		startTime = "";
		endTime = "";

		// index
		idxImg = null;
		idxImgFolder = "";
		idxImgLink = "";
		idxImgName = "";
		idxLayoutType = "";
		idxShowSeq = "1";

		// category index
		cateSubImgFolder1 = "";
		cateMainImgFolder1 = "";
		cateImgLink1 = "";
		cateLayoutType1 = "";
		cateMainImg1 = null;
		cateSubImg1 = null;
		cateMainImgName1 = "";

		cateSubImgFolder2 = "";
		cateMainImgFolder2 = "";
		cateImgLink2 = "";
		cateLayoutType2 = "";
		cateMainImg2 = null;
		cateSubImg2 = null;
		cateMainImgName2 = "";

		cateSubImgFolder3 = "";
		cateMainImgFolder3 = "";
		cateImgLink3 = "";
		cateLayoutType3 = "";
		cateMainImg3 = null;
		cateSubImg3 = null;
		cateMainImgName3 = "";

		cateSubImgFolder4 = "";
		cateMainImgFolder4 = "";
		cateImgLink4 = "";
		cateLayoutType4 = "";
		cateMainImg4 = null;
		cateSubImg4 = null;
		cateMainImgName4 = "";
		
		doClone = false;
	}

	boolean mainGoldAdvValidate() throws CoreException, ParseException, IOException {
		/**************************** 必填栏位 ****************************/
		if (StringUtils.isBlank(advName)) {
			addFieldError("advName", "请输入广告名称");
		}

		if (StringUtils.isBlank(startDate)) {
			addFieldError("startDate", "请输入起始日期");
		}

		if (StringUtils.isBlank(endDate)) {
			addFieldError("endDate", "请输入结束日期");
		}

		if (StringUtils.isBlank(advType)) {
			addFieldError("advType", "請輸入类型");
		}

		// index_V2
		if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD_V2", advType) || StringUtils.equalsIgnoreCase("PCL_MAINGOLD_V2", advType)) {
			if (StringUtils.isBlank(idxLayoutType)) {
				addFieldError("idxLayoutType", "請选择看版内容型态");
			}

			if (StringUtils.isNotBlank(idxLayoutType)) {
				if (StringUtils.isBlank(idxImgLink)) {
					addFieldError("idxImgLink", "请输入图片点击连结");
				}
				if (StringUtils.isBlank(idxImgName)) {
					addFieldError("idxImgName", "请选择黄金促销大图");
				}
			}
		} else if (StringUtils.equalsIgnoreCase("000_MAINGOLD_V2", advType)) {
			if (StringUtils.isBlank(mainCateId)) {
				addFieldError("mainCateId", "請选择馆类别");
			}

			if (StringUtils.isBlank(cateLayoutType1)) {
				addFieldError("cateLayoutType1", "請选择tab1看版内容型态");
			}

			if (StringUtils.isBlank(cateImgLink1)) {
				addFieldError("cateImgLink1", "请输入tab1图片点击连结");
			}

			if (StringUtils.isBlank(cateLayoutType2)) {
				addFieldError("cateLayoutType2", "請选择tab2看版内容型态");
			}
			if (StringUtils.isBlank(cateImgLink2)) {
				addFieldError("cateImgLink2", "请输入tab2图片点击连结");
			}

			if (StringUtils.isBlank(cateLayoutType3)) {
				addFieldError("cateLayoutType3", "請选择tab3看版内容型态");
			}
			if (StringUtils.isBlank(cateImgLink3)) {
				addFieldError("cateImgLink3", "请输入tab3图片点击连结");
			}

			if (StringUtils.isBlank(cateLayoutType4)) {
				addFieldError("cateLayoutType4", "請选择tab4看版内容型态");
			}
			if (StringUtils.isBlank(cateImgLink4)) {
				addFieldError("cateImgLink4", "请输入tab4图片点击连结");
			}

		}else if(StringUtils.equalsIgnoreCase("OUTLETS_BANNER", advType)){
			if (StringUtils.isBlank(idxLayoutType)) {
				addFieldError("idxLayoutType", "請选择看版内容型态");
			}

			if (StringUtils.isNotBlank(idxLayoutType)) {
				if (StringUtils.isBlank(idxImgLink)) {
					addFieldError("idxImgLink", "请输入图片点击连结");
				}
				if (StringUtils.isBlank(idxImgName)) {
					addFieldError("idxImgName", "请选择厂商Banner图片");
				}
			}
		} else {
			// category && index
			if (StringUtils.equalsIgnoreCase("000_MAINGOLD", advType)) {
				if (StringUtils.isBlank(mainCateId)) {
					addFieldError("mainCateId", "請选择馆类别");
				}
			}

			if (StringUtils.equalsIgnoreCase("100_MAINGOLD", advType)) {
				if (StringUtils.isBlank(childCateId)) {
					addFieldError("childCateId", "請选择次类别");
				}
			}

			if (StringUtils.isBlank(tab1Title)) {
				addFieldError("tab1Title", "請輸入tab1 title");
			}

			if (StringUtils.isBlank(tab1LayoutType)) {
				addFieldError("tab1LayoutType", "請选择tab1 layout type");
			}

			if (StringUtils.isNotBlank(tab1LayoutType)) {
				if (StringUtils.isBlank(tab1MainImgLink)) {
					addFieldError("tab1MainImgLink", "请输入tab1图檔连结");
				}
				if (StringUtils.isBlank(tab1MainImgName)) {
					addFieldError("tab1MainImgName", "请选择tab1上传檔案");
				}
			}
			if (StringUtils.equalsIgnoreCase("IMGTEXT", tab1LayoutType)) {// 图+文
				if (StringUtils.isBlank(tab1MainPromotion)) {
					addFieldError("tab1MainPromotion", "请输入tab1主标文字");
				}
				if (StringUtils.isBlank(tab1SecondPromotion)) {
					addFieldError("tab1SecondPromotion", "请输入tab1副标文字");
				}
				if (StringUtils.isBlank(tab1ProdId1)) {
					addFieldError("tab1ProdId1", "请输入tab1ProId1");
				}
				if (StringUtils.isBlank(tab1ProdId2)) {
					addFieldError("tab1ProdId2", "请输入tab1ProId2");
				}
			}

			if (StringUtils.isBlank(tab2Title)) {
				addFieldError("tab2Title", "請輸入tab2 title");
			}

			if (StringUtils.isBlank(tab2LayoutType)) {
				addFieldError("tab2LayoutType", "請选择tab2 layout type");
			}

			if (StringUtils.isNotBlank(tab2LayoutType)) {
				if (StringUtils.isBlank(tab2MainImgLink)) {
					addFieldError("tab2MainImgLink", "请输入tab2图檔连结");
				}
				if (StringUtils.isBlank(tab2MainImgName)) {
					addFieldError("tab2MainImgName", "请选择tab2上传檔案");
				}
			}
			if (StringUtils.equalsIgnoreCase("IMGTEXT", tab2LayoutType)) {// 图+文
				if (StringUtils.isBlank(tab2MainPromotion)) {
					addFieldError("tab2MainPromotion", "请输入tab2主标文字");
				}
				if (StringUtils.isBlank(tab2SecondPromotion)) {
					addFieldError("tab2SecondPromotion", "请输入tab2副标文字");
				}
				if (StringUtils.isBlank(tab2ProdId1)) {
					addFieldError("tab2ProdId1", "请输入tab2ProId1");
				}
				if (StringUtils.isBlank(tab2ProdId2)) {
					addFieldError("tab2ProdId2", "请输入tab2ProId2");
				}
			}

			if (StringUtils.isBlank(tab3Title)) {
				addFieldError("tab3Title", "請輸入tab3 title");
			}

			if (StringUtils.isBlank(tab3LayoutType)) {
				addFieldError("tab3LayoutType", "請选择tab3 layout type");
			}

			if (StringUtils.isNotBlank(tab3LayoutType)) {
				if (StringUtils.isBlank(tab3MainImgLink)) {
					addFieldError("tab3MainImgLink", "请输入tab3图檔连结");
				}
				if (StringUtils.isBlank(tab3MainImgName)) {
					addFieldError("tab3MainImgName", "请选择tab3上传檔案");
				}
			}
			if (StringUtils.equalsIgnoreCase("IMGTEXT", tab3LayoutType)) {// 图+文
				if (StringUtils.isBlank(tab3MainPromotion)) {
					addFieldError("tab3MainPromotion", "请输入tab3主标文字");
				}
				if (StringUtils.isBlank(tab3SecondPromotion)) {
					addFieldError("tab3SecondPromotion", "请输入tab3副标文字");
				}
				if (StringUtils.isBlank(tab3ProdId1)) {
					addFieldError("tab3ProdId1", "请输入tab3ProId1");
				}
				if (StringUtils.isBlank(tab3ProdId2)) {
					addFieldError("tab3ProdId2", "请输入tab3ProId2");
				}
			}

			if (StringUtils.isBlank(tab4Title)) {
				addFieldError("tab4Title", "請輸入tab4 title");
			}

			if (StringUtils.isBlank(tab4LayoutType)) {
				addFieldError("tab4LayoutType", "請选择tab4 layout type");
			}

			if (StringUtils.isNotBlank(tab4LayoutType)) {
				if (StringUtils.isBlank(tab4MainImgLink)) {
					addFieldError("tab4MainImgLink", "请输入tab4图檔连结");
				}
				if (StringUtils.isBlank(tab4MainImgName)) {
					addFieldError("tab4MainImgName", "请选择tab4上传檔案");
				}
			}
			if (StringUtils.equalsIgnoreCase("IMGTEXT", tab4LayoutType)) {// 图+文
				if (StringUtils.isBlank(tab4MainPromotion)) {
					addFieldError("tab4MainPromotion", "请输入tab4主标文字");
				}
				if (StringUtils.isBlank(tab4SecondPromotion)) {
					addFieldError("tab4SecondPromotion", "请输入tab4副标文字");
				}
				if (StringUtils.isBlank(tab4ProdId1)) {
					addFieldError("tab4ProdId1", "请输入tab4ProId1");
				}
				if (StringUtils.isBlank(tab4ProdId2)) {
					addFieldError("tab4ProdId2", "请输入tab4ProId2");
				}
			}

			if (StringUtils.isBlank(tab5Title)) {
				addFieldError("tab5Title", "請輸入tab5 title");
			}

			if (StringUtils.isBlank(tab5LayoutType)) {
				addFieldError("tab5LayoutType", "請选择tab5 layout type");
			}

			if (StringUtils.isNotBlank(tab5LayoutType)) {
				if (StringUtils.isBlank(tab5MainImgLink)) {
					addFieldError("tab5MainImgLink", "请输入tab5图檔连结");
				}
				if (StringUtils.isBlank(tab5MainImgName)) {
					addFieldError("tab5MainImgName", "请选择tab5上传檔案");
				}
			}
			if (StringUtils.equalsIgnoreCase("IMGTEXT", tab5LayoutType)) {// 图+文
				if (StringUtils.isBlank(tab5MainPromotion)) {
					addFieldError("tab5MainPromotion", "请输入tab4主标文字");
				}
				if (StringUtils.isBlank(tab5SecondPromotion)) {
					addFieldError("tab5SecondPromotion", "请输入tab5副标文字");
				}
				if (StringUtils.isBlank(tab5ProdId1)) {
					addFieldError("tab5ProdId1", "请输入tab5ProId1");
				}
				if (StringUtils.isBlank(tab5ProdId2)) {
					addFieldError("tab5ProdId2", "请输入tab5ProId2");
				}
			}
		}
		// for (String str : getFieldErrors().keySet()) {
		// logger.info("xxxx:{}", getFieldErrors().get(str));
		// }
		if (getFieldErrors().isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	public void prepare() throws Exception {
		if (null == categoryRoot) {
			categoryRoot = categoryService.getChild(0l);
		}
	}

	/**
	 * 從db讀取館首頁大看版資料
	 * 
	 * @param type
	 * @param content
	 * @throws IOException
	 */
	void readCatePropertise(String type, GenerateContent content) throws IOException {
		Properties prop = new Properties();
		Reader reader = new StringReader(content.getContents());
		prop.load(reader);
		reader.close();
		cateLayoutType1 = StringUtils.defaultString(prop.get("cateLayoutType1").toString(), "");
		cateSubImgName1 = StringUtils.defaultString(prop.get("cateSubImgName1").toString(), "");
		cateMainImgName1 = StringUtils.defaultString(prop.get("cateMainImgName1").toString(), "");
		cateImgLink1 = StringUtils.defaultString(prop.get("cateImgLink1").toString(), "");
		cateSubImgFolder1 = StringUtils.defaultString(prop.get("cateSubImgFolder1").toString(), "");
		cateMainImgFolder1 = StringUtils.defaultString(prop.get("cateMainImgFolder1").toString(), "");
		cateLayoutType2 = StringUtils.defaultString(prop.get("cateLayoutType2").toString(), "");
		cateSubImgName2 = StringUtils.defaultString(prop.get("cateSubImgName2").toString(), "");
		cateMainImgName2 = StringUtils.defaultString(prop.get("cateMainImgName2").toString(), "");
		cateImgLink2 = StringUtils.defaultString(prop.get("cateImgLink2").toString(), "");
		cateSubImgFolder2 = StringUtils.defaultString(prop.get("cateSubImgFolder2").toString(), "");
		cateMainImgFolder2 = StringUtils.defaultString(prop.get("cateMainImgFolder2").toString(), "");
		cateLayoutType3 = StringUtils.defaultString(prop.get("cateLayoutType3").toString(), "");
		cateSubImgName3 = StringUtils.defaultString(prop.get("cateSubImgName3").toString(), "");
		cateMainImgName3 = StringUtils.defaultString(prop.get("cateMainImgName3").toString(), "");
		cateImgLink3 = StringUtils.defaultString(prop.get("cateImgLink3").toString(), "");
		cateSubImgFolder3 = StringUtils.defaultString(prop.get("cateSubImgFolder3").toString(), "");
		cateMainImgFolder3 = StringUtils.defaultString(prop.get("cateMainImgFolder3").toString(), "");
		cateLayoutType4 = StringUtils.defaultString(prop.get("cateLayoutType4").toString(), "");
		cateSubImgName4 = StringUtils.defaultString(prop.get("cateSubImgName4").toString(), "");
		cateMainImgName4 = StringUtils.defaultString(prop.get("cateMainImgName4").toString(), "");
		cateImgLink4 = StringUtils.defaultString(prop.get("cateImgLink4").toString(), "");
		cateSubImgFolder4 = StringUtils.defaultString(prop.get("cateSubImgFolder4").toString(), "");
		cateMainImgFolder4 = StringUtils.defaultString(prop.get("cateMainImgFolder4").toString(), "");
	}

	/**
	 * 從db讀取首页大看版资料
	 * 
	 * @param type
	 * @param content
	 * @throws IOException
	 */
	void readIdxPropertise(String type, GenerateContent content) throws IOException {
		Properties prop = new Properties();
		Reader reader = new StringReader(content.getContents());
		prop.load(reader);
		reader.close();
		idxLayoutType = StringUtils.defaultString(prop.get("idxLayoutType").toString(), "");
		idxImgName = StringUtils.defaultString(prop.get("idxImgName").toString(), "");
		idxImgLink = StringUtils.defaultString(prop.get("idxImgLink").toString(), "");
		idxImgFolder = StringUtils.defaultString(prop.get("idxImgFolder").toString(), "");
		if (prop.containsKey("adWord")) {
			adWord = StringUtils.defaultString(prop.get("adWord").toString(), "");
		}
	}

	/**
	 * 從db讀取馆首页大看版资料
	 * 
	 * @param type
	 * @param content
	 * @throws IOException
	 */
	void readPropertise(String type, GenerateContent content) throws IOException {
		Properties prop = new Properties();
		Reader reader = new StringReader(content.getContents());
		prop.load(reader);
		reader.close();
		tab1Title = StringUtils.defaultString(prop.get("tab1Title").toString(), "");
		tab1LayoutType = StringUtils.defaultString(prop.get("tab1LayoutType").toString(), "");
		tab1MainImgName = StringUtils.defaultString(prop.get("tab1MainImgName").toString(), "");
		tab1MainImgLink = StringUtils.defaultString(prop.get("tab1MainImgLink").toString(), "");
		tab1ImgFolder = StringUtils.defaultString(prop.get("tab1ImgFolder").toString(), "");
		if (StringUtils.equalsIgnoreCase("IMGTEXT", tab1LayoutType)) {
			tab1MainPromotion = StringUtils.defaultString(prop.get("tab1MainPromotion").toString(), "");
			tab1SecondPromotion = StringUtils.defaultString(prop.get("tab1SecondPromotion").toString(), "");
			tab1ProdId1 = StringUtils.defaultString(prop.get("tab1ProdId1").toString(), "");
			tab1ProdId2 = StringUtils.defaultString(prop.get("tab1ProdId2").toString(), "");
		}
		tab2Title = StringUtils.defaultString(prop.get("tab2Title").toString(), "");
		tab2LayoutType = StringUtils.defaultString(prop.get("tab2LayoutType").toString(), "");
		tab2MainImgName = StringUtils.defaultString(prop.get("tab2MainImgName").toString(), "");
		tab2MainImgLink = StringUtils.defaultString(prop.get("tab2MainImgLink").toString(), "");
		tab2ImgFolder = StringUtils.defaultString(prop.get("tab2ImgFolder").toString(), "");
		if (StringUtils.equalsIgnoreCase("IMGTEXT", tab2LayoutType)) {
			tab2MainPromotion = StringUtils.defaultString(prop.get("tab2MainPromotion").toString(), "");
			tab2SecondPromotion = StringUtils.defaultString(prop.get("tab2SecondPromotion").toString(), "");
			tab2ProdId1 = StringUtils.defaultString(prop.get("tab2ProdId1").toString(), "");
			tab2ProdId2 = StringUtils.defaultString(prop.get("tab2ProdId2").toString(), "");
		}
		tab3Title = StringUtils.defaultString(prop.get("tab3Title").toString(), "");
		tab3LayoutType = StringUtils.defaultString(prop.get("tab3LayoutType").toString(), "");
		tab3MainImgName = StringUtils.defaultString(prop.get("tab3MainImgName").toString(), "");
		tab3MainImgLink = StringUtils.defaultString(prop.get("tab3MainImgLink").toString(), "");
		tab3ImgFolder = StringUtils.defaultString(prop.get("tab3ImgFolder").toString(), "");
		if (StringUtils.equalsIgnoreCase("IMGTEXT", tab3LayoutType)) {
			tab3MainPromotion = StringUtils.defaultString(prop.get("tab3MainPromotion").toString(), "");
			tab3SecondPromotion = StringUtils.defaultString(prop.get("tab3SecondPromotion").toString(), "");
			tab3ProdId1 = StringUtils.defaultString(prop.get("tab3ProdId1").toString(), "");
			tab3ProdId2 = StringUtils.defaultString(prop.get("tab3ProdId2").toString(), "");
		}
		tab4Title = StringUtils.defaultString(prop.get("tab4Title").toString(), "");
		tab4LayoutType = StringUtils.defaultString(prop.get("tab4LayoutType").toString(), "");
		tab4MainImgName = StringUtils.defaultString(prop.get("tab4MainImgName").toString(), "");
		tab4MainImgLink = StringUtils.defaultString(prop.get("tab4MainImgLink").toString(), "");
		tab4ImgFolder = StringUtils.defaultString(prop.get("tab4ImgFolder").toString(), "");
		if (StringUtils.equalsIgnoreCase("IMGTEXT", tab4LayoutType)) {
			tab4MainPromotion = StringUtils.defaultString(prop.get("tab4MainPromotion").toString(), "");
			tab4SecondPromotion = StringUtils.defaultString(prop.get("tab4SecondPromotion").toString(), "");
			tab4ProdId1 = StringUtils.defaultString(prop.get("tab4ProdId1").toString(), "");
			tab4ProdId2 = StringUtils.defaultString(prop.get("tab4ProdId2").toString(), "");
		}
		tab5Title = StringUtils.defaultString(prop.get("tab5Title").toString(), "");
		tab5LayoutType = StringUtils.defaultString(prop.get("tab5LayoutType").toString(), "");
		tab5MainImgName = StringUtils.defaultString(prop.get("tab5MainImgName").toString(), "");
		tab5MainImgLink = StringUtils.defaultString(prop.get("tab5MainImgLink").toString(), "");
		tab5ImgFolder = StringUtils.defaultString(prop.get("tab5ImgFolder").toString(), "");
		if (StringUtils.equalsIgnoreCase("IMGTEXT", tab5LayoutType)) {
			tab5MainPromotion = StringUtils.defaultString(prop.get("tab5MainPromotion").toString(), "");
			tab5SecondPromotion = StringUtils.defaultString(prop.get("tab5SecondPromotion").toString(), "");
			tab5ProdId1 = StringUtils.defaultString(prop.get("tab5ProdId1").toString(), "");
			tab5ProdId2 = StringUtils.defaultString(prop.get("tab5ProdId2").toString(), "");
		}
	}

	public String saveCateMainGoldAdv() throws Exception {
		double mainSize = 120;
		int mainWidth = 675;
		int mainHeight = 310;
		int subSize = 4;
		int subWidth = 88;
		int subHeight = 73;
		int error_image = 0;
		if (mainGoldAdvValidate()) {
			contents = new StringBuilder("");
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId)) {// add
					if (validateFile(cateSubImg1, "cateSubImg1", "tab1黄金促销小图", cateSubImgName1, subSize, subWidth, subHeight)) {
						contents.append(saveImgFile(cateSubImg1, cateSubImgName1, advType, "cateSubImgName1", "cateSubImgFolder1"));
					} else {
						contents.append("cateSubImgName1=").append(lineBreak);
						contents.append("cateSubImgFolder1=").append(lineBreak);
						error_image++;
					}
					if (validateFile(cateMainImg1, "cateMainImg1", "tab1黄金促销大图", cateMainImgName1, mainSize, mainWidth,
							mainHeight)) {
						contents.append(saveImgFile(cateMainImg1, cateMainImgName1, advType, "cateMainImgName1",
								"cateMainImgFolder1"));
					} else {
						contents.append("cateMainImgName1=").append(lineBreak);
						contents.append("cateMainImgFolder1=").append(lineBreak);
						error_image++;
					}

					if (validateFile(cateSubImg2, "cateSubImg2", "tab2黄金促销小图", cateSubImgName2, subSize, subWidth, subHeight)) {
						contents.append(saveImgFile(cateSubImg1, cateSubImgName2, advType, "cateSubImgName2", "cateSubImgFolder2"));
					} else {
						contents.append("cateSubImgName2=").append(lineBreak);
						contents.append("cateSubImgFolder2=").append(lineBreak);
						error_image++;
					}
					if (validateFile(cateMainImg2, "cateMainImg2", "tab2黄金促销大图", cateMainImgName2, mainSize, mainWidth,
							mainHeight)) {
						contents.append(saveImgFile(cateMainImg2, cateMainImgName2, advType, "cateMainImgName2",
								"cateMainImgFolder2"));
					} else {
						contents.append("cateMainImgName2=").append(lineBreak);
						contents.append("cateMainImgFolder2=").append(lineBreak);
						error_image++;
					}

					if (validateFile(cateSubImg3, "cateSubImg3", "tab3黄金促销小图", cateSubImgName3, subSize, subWidth, subHeight)) {
						contents.append(saveImgFile(cateSubImg3, cateSubImgName3, advType, "cateSubImgName3", "cateSubImgFolder3"));
					} else {
						contents.append("cateSubImgName3=").append(lineBreak);
						contents.append("cateSubImgFolder3=").append(lineBreak);
						error_image++;
					}
					if (validateFile(cateMainImg3, "cateMainImg3", "tab3黄金促销大图", cateMainImgName3, mainSize, mainWidth,
							mainHeight)) {
						contents.append(saveImgFile(cateMainImg3, cateMainImgName3, advType, "cateMainImgName3",
								"cateMainImgFolder3"));
					} else {
						contents.append("cateMainImgName3=").append(lineBreak);
						contents.append("cateMainImgFolder3=").append(lineBreak);
						error_image++;
					}

					if (validateFile(cateSubImg4, "cateSubImg4", "tab4黄金促销小图", cateSubImgName4, subSize, subWidth, subHeight)) {
						contents.append(saveImgFile(cateSubImg4, cateSubImgName4, advType, "cateSubImgName4", "cateSubImgFolder4"));
					} else {
						contents.append("cateSubImgName4=").append(lineBreak);
						contents.append("cateSubImgFolder4=").append(lineBreak);
						error_image++;
					}
					if (validateFile(cateMainImg4, "cateMainImg4", "tab4黄金促销大图", cateMainImgName4, mainSize, mainWidth,
							mainHeight)) {
						contents.append(saveImgFile(cateMainImg4, cateMainImgName4, advType, "cateMainImgName4",
								"cateMainImgFolder4"));
					} else {
						contents.append("cateMainImgName4=").append(lineBreak);
						contents.append("cateMainImgFolder4=").append(lineBreak);
						error_image++;
					}
				} else {// update
					if (null == cateSubImg1) {
						contents.append("cateSubImgName1=").append(cateSubImgName1).append(lineBreak);
						contents.append("cateSubImgFolder1=").append(cateSubImgFolder1).append(lineBreak);
					} else {
						if (validateFile(cateSubImg1, "cateSubImg1", "tab1黄金促销小图", cateSubImgName1, subSize, subWidth, subHeight)) {
							contents
									.append(saveImgFile(cateSubImg1, cateSubImgName1, advType, "cateSubImgName1", "cateSubImgFolder1"));
						} else {
							contents.append("cateSubImgName1=").append(lineBreak);
							contents.append("cateSubImgFolder1=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateMainImg1) {
						contents.append("cateMainImgName1=").append(cateMainImgName1).append(lineBreak);
						contents.append("cateMainImgFolder1=").append(cateMainImgFolder1).append(lineBreak);
					} else {
						if (validateFile(cateMainImg1, "cateMainImg1", "tab1黄金促销大图", cateMainImgName1, mainSize, mainWidth,
								mainHeight)) {
							contents.append(saveImgFile(cateMainImg1, cateMainImgName1, advType, "cateMainImgName1",
									"cateMainImgFolder1"));
						} else {
							contents.append("cateMainImgName1=").append(lineBreak);
							contents.append("cateMainImgFolder1=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateSubImg2) {
						contents.append("cateSubImgName2=").append(cateSubImgName2).append(lineBreak);
						contents.append("cateSubImgFolder2=").append(cateSubImgFolder2).append(lineBreak);
					} else {
						if (validateFile(cateSubImg2, "cateSubImg2", "tab2黄金促销小图", cateSubImgName2, subSize, subWidth, subHeight)) {
							contents
									.append(saveImgFile(cateSubImg2, cateSubImgName2, advType, "cateSubImgName2", "cateSubImgFolder2"));
						} else {
							contents.append("cateSubImgName2=").append(lineBreak);
							contents.append("cateSubImgFolder2=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateMainImg2) {
						contents.append("cateMainImgName2=").append(cateMainImgName2).append(lineBreak);
						contents.append("cateMainImgFolder2=").append(cateMainImgFolder2).append(lineBreak);
					} else {
						if (validateFile(cateMainImg2, "cateMainImg2", "tab2黄金促销大图", cateMainImgName2, mainSize, mainWidth,
								mainHeight)) {
							contents.append(saveImgFile(cateMainImg2, cateMainImgName2, advType, "cateMainImgName2",
									"cateMainImgFolder2"));
						} else {
							contents.append("cateMainImgName2=").append(lineBreak);
							contents.append("cateMainImgFolder2=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateSubImg3) {
						contents.append("cateSubImgName3=").append(cateSubImgName3).append(lineBreak);
						contents.append("cateSubImgFolder3=").append(cateSubImgFolder3).append(lineBreak);
					} else {
						if (validateFile(cateSubImg3, "cateSubImg3", "tab3黄金促销小图", cateSubImgName3, subSize, subWidth, subHeight)) {
							contents
									.append(saveImgFile(cateSubImg3, cateSubImgName3, advType, "cateSubImgName3", "cateSubImgFolder3"));
						} else {
							contents.append("cateSubImgName3=").append(lineBreak);
							contents.append("cateSubImgFolder3=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateMainImg3) {
						contents.append("cateMainImgName3=").append(cateMainImgName3).append(lineBreak);
						contents.append("cateMainImgFolder3=").append(cateMainImgFolder3).append(lineBreak);
					} else {
						if (validateFile(cateMainImg3, "cateMainImg3", "tab3黄金促销大图", cateMainImgName3, mainSize, mainWidth,
								mainHeight)) {
							contents.append(saveImgFile(cateMainImg3, cateMainImgName3, advType, "cateMainImgName3",
									"cateMainImgFolder3"));
						} else {
							contents.append("cateMainImgName3=").append(lineBreak);
							contents.append("cateMainImgFolder3=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateSubImg4) {
						contents.append("cateSubImgName4=").append(cateSubImgName4).append(lineBreak);
						contents.append("cateSubImgFolder4=").append(cateSubImgFolder4).append(lineBreak);
					} else {
						if (validateFile(cateSubImg4, "cateSubImg4", "tab4黄金促销小图", cateSubImgName4, subSize, subWidth, subHeight)) {
							contents
									.append(saveImgFile(cateSubImg4, cateSubImgName4, advType, "cateSubImgName4", "cateSubImgFolder4"));
						} else {
							contents.append("cateSubImgName4=").append(lineBreak);
							contents.append("cateSubImgFolder4=").append(lineBreak);
							error_image++;
						}
					}

					if (null == cateMainImg4) {
						contents.append("cateMainImgName4=").append(cateMainImgName4).append(lineBreak);
						contents.append("cateMainImgFolder4=").append(cateMainImgFolder4).append(lineBreak);
					} else {
						if (validateFile(cateMainImg4, "cateMainImg4", "tab4黄金促销大图", cateMainImgName4, mainSize, mainWidth,
								mainHeight)) {
							contents.append(saveImgFile(cateMainImg4, cateMainImgName4, advType, "cateMainImgName4",
									"cateMainImgFolder4"));
						} else {
							contents.append("cateMainImgName4=").append(lineBreak);
							contents.append("cateMainImgFolder4=").append(lineBreak);
							error_image++;
						}
					}
				}
				contents.append("cateImgLink1=").append(cateImgLink1).append(lineBreak);
				contents.append("cateLayoutType1=").append(cateLayoutType1).append(lineBreak);
				contents.append("cateImgLink2=").append(cateImgLink2).append(lineBreak);
				contents.append("cateLayoutType2=").append(cateLayoutType2).append(lineBreak);
				contents.append("cateImgLink3=").append(cateImgLink3).append(lineBreak);
				contents.append("cateLayoutType3=").append(cateLayoutType3).append(lineBreak);
				contents.append("cateImgLink4=").append(cateImgLink4).append(lineBreak);
				contents.append("cateLayoutType4=").append(cateLayoutType4).append(lineBreak);
				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}
				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(PATTERN_DATE_FORMAT.parse(startDate + " " + startTime + ":00"));
				advertise.setEndDate(PATTERN_DATE_FORMAT.parse(endDate + " " + endTime + ":59"));
				if (error_image > 0) {
					advertise.setAdvStatus("90");
				} else {
					advertise.setAdvStatus(advStatus);
				}
				position.setMainCateId(Long.parseLong(mainCateId));
				content.setContents(contents.toString());

				if (StringUtils.isBlank(advId)) {
					generateService.saveGenerateCombine(advertise, position, content);
				} else {
					generateService.updateGenerateCombine(advertise, position, content);
				}

				contents.setLength(0);

				// 存檔後立刻執行產生檔案的邏輯
				generateService.generateCateMainGoldAdv(null);
			}
		}
		advId = advertise.getId().toString();
		if (getFieldErrors().isEmpty()) {
			addActionMessage("储存成功");
		} else {
			addActionMessage("储存成功,部份栏位资料有误");
		}
		return editCateMainGoldAdv();
	}

	public String saveIdxMainGoldAdv() throws Exception {
		double idxSize = 120;
		int idxWidth = 675;
		int idxHeight = 310;
		int error_image = 0;
		if (mainGoldAdvValidate()) {
			contents = new StringBuilder("");
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId) && !doClone) {// add
					if (validateFile(idxImg, "idxImg", "黄金促销大图", idxImgName, idxSize, idxWidth, idxHeight)) {
						contents.append(saveImgFile(idxImg, idxImgName, advType, "idxImgName", "idxImgFolder"));
					} else {
						contents.append("idxImgName=").append(lineBreak);
						contents.append("idxImgFolder=").append(lineBreak);
						error_image++;
					}
				} else {// update
					if (null == idxImg) {
						contents.append("idxImgName=").append(idxImgName).append(lineBreak);
						contents.append("idxImgFolder=").append(idxImgFolder).append(lineBreak);
					} else {
						if (validateFile(idxImg, "idxImg", "黄金促销大图", idxImgName, idxSize, idxWidth, idxHeight)) {
							contents.append(saveImgFile(idxImg, idxImgName, advType, "idxImgName", "idxImgFolder"));
						} else {
							contents.append("idxImgName=").append(lineBreak);
							contents.append("idxImgFolder=").append(lineBreak);
							error_image++;
						}
					}
				}
				contents.append("idxImgLink=").append(idxImgLink).append(lineBreak);
				if (StringUtils.isNotBlank(adWord)) {
					contents.append("adWord=").append(adWord).append(lineBreak);
				}
				contents.append("idxLayoutType=").append(idxLayoutType).append(lineBreak);
				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}
				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(PATTERN_DATE_FORMAT.parse(startDate + " " + startTime + ":00"));
				advertise.setEndDate(PATTERN_DATE_FORMAT.parse(endDate + " " + endTime + ":59"));
				if (error_image > 0) {
					advertise.setAdvStatus("90");
				} else {
					advertise.setAdvStatus(advStatus);
				}
				content.setContents(contents.toString());
				content.setShowSeq(Integer.parseInt(idxShowSeq));

				if (StringUtils.isBlank(advId)) {
					generateService.saveGenerateCombine(advertise, position, content);
				} else {
					generateService.updateGenerateCombine(advertise, position, content);
				}
				contents.setLength(0);
				if( StringUtils.equalsIgnoreCase(from, "PCL") ) {
					generateService.generatePclMainGoldAdv_V2(null);
				} else {
					generateService.generateIdxMainGoldAdv_V2(null);
				}
			}
		}
		advId = advertise.getId().toString();
		if (getFieldErrors().isEmpty()) {
			addActionMessage("储存成功");
		} else {
			addActionMessage("储存成功,部份栏位资料有误");
		}
		return editIdxMainGoldAdv_V2();
	}
	
	public String saveOutletsBannerAdv() throws Exception {
		double idxSize = 35;
		int idxWidth = 340;
		int idxHeight = 180;
		int error_image = 0;
		if (mainGoldAdvValidate()) {
			contents = new StringBuilder("");
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId) && !doClone) {// add
					if (validateFile(idxImg, "idxImg", "厂商Banner图片", idxImgName, idxSize, idxWidth, idxHeight)) {
						contents.append(saveImgFile(idxImg, idxImgName, advType, "idxImgName", "idxImgFolder"));
					} else {
						contents.append("idxImgName=").append(lineBreak);
						contents.append("idxImgFolder=").append(lineBreak);
						error_image++;
					}
				} else {// update
					if (null == idxImg) {
						contents.append("idxImgName=").append(idxImgName).append(lineBreak);
						contents.append("idxImgFolder=").append(idxImgFolder).append(lineBreak);
					} else {
						if (validateFile(idxImg, "idxImg", "厂商Banner图片", idxImgName, idxSize, idxWidth, idxHeight)) {
							contents.append(saveImgFile(idxImg, idxImgName, advType, "idxImgName", "idxImgFolder"));
						} else {
							contents.append("idxImgName=").append(lineBreak);
							contents.append("idxImgFolder=").append(lineBreak);
							error_image++;
						}
					}
				}
				contents.append("idxImgLink=").append(idxImgLink).append(lineBreak);
				if (StringUtils.isNotBlank(adWord)) {
					contents.append("adWord=").append(adWord).append(lineBreak);
				}
				contents.append("idxLayoutType=").append(idxLayoutType).append(lineBreak);
				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}
				position.setMainCateId(Long.parseLong("7447"));
				
				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(PATTERN_DATE_FORMAT.parse(startDate + " " + startTime + ":00"));
				advertise.setEndDate(PATTERN_DATE_FORMAT.parse(endDate + " " + endTime + ":59"));
				if (error_image > 0) {
					advertise.setAdvStatus("90");
				} else {
					advertise.setAdvStatus(advStatus);
				}
				content.setContents(contents.toString());
				content.setShowSeq(Integer.parseInt(idxShowSeq));

				if (StringUtils.isBlank(advId)) {
					generateService.saveGenerateCombine(advertise, position, content);
				} else {
					generateService.updateGenerateCombine(advertise, position, content);
				}
				contents.setLength(0);
				generateService.generateOutletsBannerAdv();
			}
		}
		advId = advertise.getId().toString();
		if (getFieldErrors().isEmpty()) {
			addActionMessage("储存成功");
		} else {
			addActionMessage("储存成功,部份栏位资料有误");
		}
		return editOutletsBannerAdv();
	}

	EventImage saveImgFile(File imgFile, String fileName, String advType) throws Exception {
		try {
			eventImage = new EventImage();
			eventImage.setImgType(fileName.substring(fileName.lastIndexOf("."), fileName.length()));
			eventImage = generateService.saveEventImage(eventImage);
			boolean result = GenerateHelper.uploadImage(eventImage, imgFile, advType);
			if (result) {
				return eventImage;
			} else {
				return null;
			}
		} catch (Exception e) {
			logger.info("exception :{}", e.getMessage());
		}
		return null;
	}

	String saveImgFile(File imgFile, String fileName, String advType, String imgName, String imgFolder) throws Exception {
		StringBuffer sb = new StringBuffer();
		try {
			String today = FastDateFormat.getInstance(EcConstant.DEFAULT_PATTERN_DATE).format(DateUtil.getToday().getTime());
			eventImage = new EventImage();
			eventImage.setImgType(fileName.substring(fileName.lastIndexOf("."), fileName.length()));
			eventImage = generateService.saveEventImage(eventImage);
			boolean result = GenerateHelper.uploadImage(eventImage, imgFile, advType);
			if (result) {
				sb.append(imgName + "=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(lineBreak);
				sb.append(imgFolder + "=").append(today).append(lineBreak);
			} else {
				sb.append(imgName + "=").append(lineBreak);
				sb.append(imgFolder + "=").append(lineBreak);
			}
		} catch (Exception e) {
			logger.info("exception :{}", e.getMessage());
		}
		return sb.toString();
	}

	public String saveMainGoldAdv() throws Exception {
		boolean result = false;
		String today = FastDateFormat.getInstance(EcConstant.DEFAULT_PATTERN_DATE).format(DateUtil.getToday().getTime());

		if (mainGoldAdvValidate()) {
			contents = new StringBuilder("");
			// upload file
			if (GenerateHelper.mkDir(advType)) {
				if (StringUtils.isBlank(advId)) {// add
					eventImage = saveImgFile(tab1MainImg, tab1MainImgName, advType);
					if (null != eventImage) {
						contents.append("tab1MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
								lineBreak);
						contents.append("tab1ImgFolder=").append(today).append(lineBreak);
					}

					eventImage = saveImgFile(tab2MainImg, tab2MainImgName, advType);
					if (null != eventImage) {
						contents.append("tab2MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
								lineBreak);
						contents.append("tab2ImgFolder=").append(today).append(lineBreak);
					}

					eventImage = saveImgFile(tab3MainImg, tab3MainImgName, advType);
					if (null != eventImage) {
						contents.append("tab3MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
								lineBreak);
						contents.append("tab3ImgFolder=").append(today).append(lineBreak);
					}

					eventImage = saveImgFile(tab4MainImg, tab4MainImgName, advType);
					if (null != eventImage) {
						contents.append("tab4MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
								lineBreak);
						contents.append("tab4ImgFolder=").append(today).append(lineBreak);
					}

					eventImage = saveImgFile(tab5MainImg, tab5MainImgName, advType);
					if (null != eventImage) {
						contents.append("tab5MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
								lineBreak);
						contents.append("tab5ImgFolder=").append(today).append(lineBreak);
					}
				} else {// update
					if (null == tab1MainImg) {
						contents.append("tab1MainImgName=").append(tab1MainImgName).append(lineBreak);
						contents.append("tab1ImgFolder=").append(tab1ImgFolder).append(lineBreak);
					} else {
						eventImage = saveImgFile(tab1MainImg, tab1MainImgName, advType);
						if (null != eventImage) {
							contents.append("tab1MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
									lineBreak);
							contents.append("tab1ImgFolder=").append(today).append(lineBreak);
						}
					}

					if (null == tab2MainImg) {
						contents.append("tab2MainImgName=").append(tab2MainImgName).append(lineBreak);
						contents.append("tab2ImgFolder=").append(tab2ImgFolder).append(lineBreak);
					} else {
						eventImage = saveImgFile(tab2MainImg, tab2MainImgName, advType);
						if (null != eventImage) {
							contents.append("tab2MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
									lineBreak);
							contents.append("tab2ImgFolder=").append(today).append(lineBreak);
						}

					}
					if (null == tab3MainImg) {
						contents.append("tab3MainImgName=").append(tab3MainImgName).append(lineBreak);
						contents.append("tab3ImgFolder=").append(tab3ImgFolder).append(lineBreak);
					} else {
						eventImage = saveImgFile(tab3MainImg, tab3MainImgName, advType);
						if (null != eventImage) {
							contents.append("tab3MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
									lineBreak);
							contents.append("tab3ImgFolder=").append(today).append(lineBreak);
						}
					}

					if (null == tab4MainImg) {
						contents.append("tab4MainImgName=").append(tab4MainImgName).append(lineBreak);
						contents.append("tab4ImgFolder=").append(tab4ImgFolder).append(lineBreak);
					} else {
						eventImage = saveImgFile(tab4MainImg, tab4MainImgName, advType);
						if (null != eventImage) {
							contents.append("tab4MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
									lineBreak);
							contents.append("tab4ImgFolder=").append(today).append(lineBreak);
						}
					}

					if (null == tab5MainImg) {
						contents.append("tab5MainImgName=").append(tab5MainImgName).append(lineBreak);
						contents.append("tab5ImgFolder=").append(tab5ImgFolder).append(lineBreak);
					} else {
						eventImage = saveImgFile(tab5MainImg, tab5MainImgName, advType);
						if (null != eventImage) {
							contents.append("tab5MainImgName=").append(eventImage.getUuid()).append(eventImage.getImgType()).append(
									lineBreak);
							contents.append("tab5ImgFolder=").append(today).append(lineBreak);
						}
					}
				}
				contents.append("tab1MainImgLink=").append(tab1MainImgLink).append(lineBreak);
				contents.append("tab1LayoutType=").append(tab1LayoutType).append(lineBreak);
				contents.append("tab1Title=").append(tab1Title).append(lineBreak);
				if (StringUtils.equalsIgnoreCase("IMGTEXT", tab1LayoutType)) {
					contents.append("tab1MainPromotion=").append(tab1MainPromotion).append(lineBreak);
					contents.append("tab1SecondPromotion=").append(tab1SecondPromotion).append(lineBreak);
					contents.append("tab1ProdId1=").append(tab1ProdId1).append(lineBreak);
					contents.append("tab1ProdId2=").append(tab1ProdId2).append(lineBreak);
				}
				contents.append("tab2MainImgLink=").append(tab2MainImgLink).append(lineBreak);
				contents.append("tab2LayoutType=").append(tab2LayoutType).append(lineBreak);
				contents.append("tab2Title=").append(tab2Title).append(lineBreak);
				if (StringUtils.equalsIgnoreCase("IMGTEXT", tab2LayoutType)) {
					contents.append("tab2MainPromotion=").append(tab2MainPromotion).append(lineBreak);
					contents.append("tab2SecondPromotion=").append(tab2SecondPromotion).append(lineBreak);
					contents.append("tab2ProdId1=").append(tab2ProdId1).append(lineBreak);
					contents.append("tab2ProdId2=").append(tab2ProdId2).append(lineBreak);
				}
				contents.append("tab3MainImgLink=").append(tab3MainImgLink).append(lineBreak);
				contents.append("tab3LayoutType=").append(tab3LayoutType).append(lineBreak);
				contents.append("tab3Title=").append(tab3Title).append(lineBreak);
				if (StringUtils.equalsIgnoreCase("IMGTEXT", tab3LayoutType)) {
					contents.append("tab3MainPromotion=").append(tab3MainPromotion).append(lineBreak);
					contents.append("tab3SecondPromotion=").append(tab3SecondPromotion).append(lineBreak);
					contents.append("tab3ProdId1=").append(tab3ProdId1).append(lineBreak);
					contents.append("tab3ProdId2=").append(tab3ProdId2).append(lineBreak);
				}
				contents.append("tab4MainImgLink=").append(tab4MainImgLink).append(lineBreak);
				contents.append("tab4LayoutType=").append(tab4LayoutType).append(lineBreak);
				contents.append("tab4Title=").append(tab4Title).append(lineBreak);
				if (StringUtils.equalsIgnoreCase("IMGTEXT", tab4LayoutType)) {
					contents.append("tab4MainPromotion=").append(tab4MainPromotion).append(lineBreak);
					contents.append("tab4SecondPromotion=").append(tab4SecondPromotion).append(lineBreak);
					contents.append("tab4ProdId1=").append(tab4ProdId1).append(lineBreak);
					contents.append("tab4ProdId2=").append(tab4ProdId2).append(lineBreak);
				}
				contents.append("tab5MainImgLink=").append(tab5MainImgLink).append(lineBreak);
				contents.append("tab5LayoutType=").append(tab5LayoutType).append(lineBreak);
				contents.append("tab5Title=").append(tab5Title).append(lineBreak);
				if (StringUtils.equalsIgnoreCase("IMGTEXT", tab5LayoutType)) {
					contents.append("tab5MainPromotion=").append(tab5MainPromotion).append(lineBreak);
					contents.append("tab5SecondPromotion=").append(tab5SecondPromotion).append(lineBreak);
					contents.append("tab5ProdId1=").append(tab5ProdId1).append(lineBreak);
					contents.append("tab5ProdId2=").append(tab5ProdId2).append(lineBreak);
				}

				if (StringUtils.isBlank(advId)) {
					advertise = new GenerateAdvertise();
					position = new GeneratePosition();
					content = new GenerateContent();
				} else {
					advertise = generateService.get(Long.parseLong(advId));
					position = generateService.getGeneratePositionByAdvId(Long.parseLong(advId)).get(0);
					content = generateService.getGenerateContentByAdvId(Long.parseLong(advId)).get(0);
				}

				// set advertise
				advertise.setAdvType(advType);
				advertise.setAdvName(advName.trim());
				advertise.setStartDate(EcConstant.PATTERN_DATE_FORMAT.parse(startDate));
				advertise.setEndDate(EcConstant.PATTERN_DATE_FORMAT.parse(endDate));
				advertise.setAdvStatus(advStatus);
				if (StringUtils.equalsIgnoreCase("000_MAINGOLD", advType)) {
					position.setMainCateId(Long.parseLong(mainCateId));
				}
				if (StringUtils.equalsIgnoreCase("100_MAINGOLD", advType)) {
					position.setMainCateId(Long.parseLong(mainCateId));
					position.setChildCateId(Long.parseLong(childCateId));
				}
				content.setContents(contents.toString());
				// 用此判斷圖檔是否有上傳成功
				// Str
				if (StringUtils.countMatches(content.getContents(), "MainImgName") == 5) {
					if (StringUtils.isBlank(advId)) {
						result = generateService.saveGenerateCombine(advertise, position, content);
					} else {
						result = generateService.updateGenerateCombine(advertise, position, content);
					}
				} else {
					result = false;
				}
				contents.setLength(0);
				if (!result) {
					if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD", advType)) {
						return "editIdxMainGoldAdv";
					} else {
						return "editMainGoldAdv";
					}
				} else {
					if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD", advType)) {
						return "listIdxAdv";
					} else {
						return "listAdv";
					}
				}
			}
		}
		if (StringUtils.equalsIgnoreCase("IDX_MAINGOLD", advType)) {
			return "editIdxMainGoldAdv";
		} else {
			return "editMainGoldAdv";
		}
	}

	public void setAdvertise(GenerateAdvertise advertise) {
		this.advertise = advertise;
	}

	public void setAdvId(String advId) {
		this.advId = advId;
	}

	public void setAdvName(String advName) {
		this.advName = advName;
	}

	public void setAdvStatus(String advStatus) {
		this.advStatus = advStatus;
	}

	public void setAdvType(String advType) {
		this.advType = advType;
	}

	public void setCategoryRoot(List<Category> categoryRoot) {
		this.categoryRoot = categoryRoot;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCateImgLink1(String cateImgLink1) {
		this.cateImgLink1 = cateImgLink1;
	}

	public void setCateImgLink2(String cateImgLink2) {
		this.cateImgLink2 = cateImgLink2;
	}

	public void setCateImgLink3(String cateImgLink3) {
		this.cateImgLink3 = cateImgLink3;
	}

	public void setCateImgLink4(String cateImgLink4) {
		this.cateImgLink4 = cateImgLink4;
	}

	public void setCateLayoutType1(String cateLayoutType1) {
		this.cateLayoutType1 = cateLayoutType1;
	}

	public void setCateLayoutType2(String cateLayoutType2) {
		this.cateLayoutType2 = cateLayoutType2;
	}

	public void setCateLayoutType3(String cateLayoutType3) {
		this.cateLayoutType3 = cateLayoutType3;
	}

	public void setCateLayoutType4(String cateLayoutType4) {
		this.cateLayoutType4 = cateLayoutType4;
	}

	public void setCateMainImg1(File cateMainImg1) {
		this.cateMainImg1 = cateMainImg1;
	}

	public void setCateMainImg2(File cateMainImg2) {
		this.cateMainImg2 = cateMainImg2;
	}

	public void setCateMainImg3(File cateMainImg3) {
		this.cateMainImg3 = cateMainImg3;
	}

	public void setCateMainImg4(File cateMainImg4) {
		this.cateMainImg4 = cateMainImg4;
	}

	public void setCateMainImgFolder1(String cateMainImgFolder1) {
		this.cateMainImgFolder1 = cateMainImgFolder1;
	}

	public void setCateMainImgFolder2(String cateMainImgFolder2) {
		this.cateMainImgFolder2 = cateMainImgFolder2;
	}

	public void setCateMainImgFolder3(String cateMainImgFolder3) {
		this.cateMainImgFolder3 = cateMainImgFolder3;
	}

	public void setCateMainImgFolder4(String cateMainImgFolder4) {
		this.cateMainImgFolder4 = cateMainImgFolder4;
	}

	public void setCateMainImgName1(String cateMainImgName1) {
		this.cateMainImgName1 = cateMainImgName1;
	}

	public void setCateMainImgName2(String cateMainImgName2) {
		this.cateMainImgName2 = cateMainImgName2;
	}

	public void setCateMainImgName3(String cateMainImgName3) {
		this.cateMainImgName3 = cateMainImgName3;
	}

	public void setCateMainImgName4(String cateMainImgName4) {
		this.cateMainImgName4 = cateMainImgName4;
	}

	public void setCateSubImg1(File cateSubImg1) {
		this.cateSubImg1 = cateSubImg1;
	}

	public void setCateSubImg2(File cateSubImg2) {
		this.cateSubImg2 = cateSubImg2;
	}

	public void setCateSubImg3(File cateSubImg3) {
		this.cateSubImg3 = cateSubImg3;
	}

	public void setCateSubImg4(File cateSubImg4) {
		this.cateSubImg4 = cateSubImg4;
	}

	public void setCateSubImgFolder1(String cateSubImgFolder1) {
		this.cateSubImgFolder1 = cateSubImgFolder1;
	}

	public void setCateSubImgFolder2(String cateSubImgFolder2) {
		this.cateSubImgFolder2 = cateSubImgFolder2;
	}

	public void setCateSubImgFolder3(String cateSubImgFolder3) {
		this.cateSubImgFolder3 = cateSubImgFolder3;
	}

	public void setCateSubImgFolder4(String cateSubImgFolder4) {
		this.cateSubImgFolder4 = cateSubImgFolder4;
	}

	public void setCateSubImgName1(String cateSubImgName1) {
		this.cateSubImgName1 = cateSubImgName1;
	}

	public void setCateSubImgName2(String cateSubImgName2) {
		this.cateSubImgName2 = cateSubImgName2;
	}

	public void setCateSubImgName3(String cateSubImgName3) {
		this.cateSubImgName3 = cateSubImgName3;
	}

	public void setCateSubImgName4(String cateSubImgName4) {
		this.cateSubImgName4 = cateSubImgName4;
	}

	public void setChildCateId(String childCateId) {
		this.childCateId = childCateId;
	}

	public void setContent(GenerateContent content) {
		this.content = content;
	}

	public void setContents(StringBuilder contents) {
		this.contents = contents;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public void setEventImage(EventImage eventImage) {
		this.eventImage = eventImage;
	}

	public void setGenerateService(GenerateService generateService) {
		this.generateService = generateService;
	}

	public void setIdxImg(File idxImg) {
		this.idxImg = idxImg;
	}

	public void setIdxImgFolder(String idxImgFolder) {
		this.idxImgFolder = idxImgFolder;
	}

	public void setIdxImgLink(String idxImgLink) {
		this.idxImgLink = idxImgLink;
	}

	public void setIdxImgName(String idxImgName) {
		this.idxImgName = idxImgName;
	}

	public void setIdxLayoutType(String idxLayoutType) {
		this.idxLayoutType = idxLayoutType;
	}

	public void setIdxShowSeq(String idxShowSeq) {
		this.idxShowSeq = idxShowSeq;
	}

	public void setMainCateId(String mainCateId) {
		this.mainCateId = mainCateId;
	}

	public void setPosition(GeneratePosition position) {
		this.position = position;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public void setTab1ImgFolder(String tab1ImgFolder) {
		this.tab1ImgFolder = tab1ImgFolder;
	}

	public void setTab1LayoutType(String tab1LayoutType) {
		this.tab1LayoutType = tab1LayoutType;
	}

	public void setTab1MainImg(File tab1MainImg) {
		this.tab1MainImg = tab1MainImg;
	}

	public void setTab1MainImgLink(String tab1MainImgLink) {
		this.tab1MainImgLink = tab1MainImgLink;
	}

	public void setTab1MainImgName(String tab1MainImgName) {
		this.tab1MainImgName = tab1MainImgName;
	}

	public void setTab1MainPromotion(String tab1MainPromotion) {
		this.tab1MainPromotion = tab1MainPromotion;
	}

	public void setTab1ProdId1(String tab1ProdId1) {
		this.tab1ProdId1 = tab1ProdId1;
	}

	public void setTab1ProdId2(String tab1ProdId2) {
		this.tab1ProdId2 = tab1ProdId2;
	}

	public void setTab1SecondPromotion(String tab1SecondPromotion) {
		this.tab1SecondPromotion = tab1SecondPromotion;
	}

	public void setTab1Title(String tab1Title) {
		this.tab1Title = tab1Title;
	}

	public void setTab2ImgFolder(String tab2ImgFolder) {
		this.tab2ImgFolder = tab2ImgFolder;
	}

	public void setTab2LayoutType(String tab2LayoutType) {
		this.tab2LayoutType = tab2LayoutType;
	}

	public void setTab2MainImg(File tab2MainImg) {
		this.tab2MainImg = tab2MainImg;
	}

	public void setTab2MainImgLink(String tab2MainImgLink) {
		this.tab2MainImgLink = tab2MainImgLink;
	}

	public void setTab2MainImgName(String tab2MainImgName) {
		this.tab2MainImgName = tab2MainImgName;
	}

	public void setTab2MainPromotion(String tab2MainPromotion) {
		this.tab2MainPromotion = tab2MainPromotion;
	}

	public void setTab2ProdId1(String tab2ProdId1) {
		this.tab2ProdId1 = tab2ProdId1;
	}

	public void setTab2ProdId2(String tab2ProdId2) {
		this.tab2ProdId2 = tab2ProdId2;
	}

	public void setTab2SecondPromotion(String tab2SecondPromotion) {
		this.tab2SecondPromotion = tab2SecondPromotion;
	}

	public void setTab2Title(String tab2Title) {
		this.tab2Title = tab2Title;
	}

	public void setTab3ImgFolder(String tab3ImgFolder) {
		this.tab3ImgFolder = tab3ImgFolder;
	}

	public void setTab3LayoutType(String tab3LayoutType) {
		this.tab3LayoutType = tab3LayoutType;
	}

	public void setTab3MainImg(File tab3MainImg) {
		this.tab3MainImg = tab3MainImg;
	}

	public void setTab3MainImgLink(String tab3MainImgLink) {
		this.tab3MainImgLink = tab3MainImgLink;
	}

	public void setTab3MainImgName(String tab3MainImgName) {
		this.tab3MainImgName = tab3MainImgName;
	}

	public void setTab3MainPromotion(String tab3MainPromotion) {
		this.tab3MainPromotion = tab3MainPromotion;
	}

	public void setTab3ProdId1(String tab3ProdId1) {
		this.tab3ProdId1 = tab3ProdId1;
	}

	public void setTab3ProdId2(String tab3ProdId2) {
		this.tab3ProdId2 = tab3ProdId2;
	}

	public void setTab3SecondPromotion(String tab3SecondPromotion) {
		this.tab3SecondPromotion = tab3SecondPromotion;
	}

	public void setTab3Title(String tab3Title) {
		this.tab3Title = tab3Title;
	}

	public void setTab4ImgFolder(String tab4ImgFolder) {
		this.tab4ImgFolder = tab4ImgFolder;
	}

	public void setTab4LayoutType(String tab4LayoutType) {
		this.tab4LayoutType = tab4LayoutType;
	}

	public void setTab4MainImg(File tab4MainImg) {
		this.tab4MainImg = tab4MainImg;
	}

	public void setTab4MainImgLink(String tab4MainImgLink) {
		this.tab4MainImgLink = tab4MainImgLink;
	}

	public void setTab4MainImgName(String tab4MainImgName) {
		this.tab4MainImgName = tab4MainImgName;
	}

	public void setTab4MainPromotion(String tab4MainPromotion) {
		this.tab4MainPromotion = tab4MainPromotion;
	}

	public void setTab4ProdId1(String tab4ProdId1) {
		this.tab4ProdId1 = tab4ProdId1;
	}

	public void setTab4ProdId2(String tab4ProdId2) {
		this.tab4ProdId2 = tab4ProdId2;
	}

	public void setTab4SecondPromotion(String tab4SecondPromotion) {
		this.tab4SecondPromotion = tab4SecondPromotion;
	}

	public void setTab4Title(String tab4Title) {
		this.tab4Title = tab4Title;
	}

	public void setTab5ImgFolder(String tab5ImgFolder) {
		this.tab5ImgFolder = tab5ImgFolder;
	}

	public void setTab5LayoutType(String tab5LayoutType) {
		this.tab5LayoutType = tab5LayoutType;
	}

	public void setTab5MainImg(File tab5MainImg) {
		this.tab5MainImg = tab5MainImg;
	}

	public void setTab5MainImgLink(String tab5MainImgLink) {
		this.tab5MainImgLink = tab5MainImgLink;
	}

	public void setTab5MainImgName(String tab5MainImgName) {
		this.tab5MainImgName = tab5MainImgName;
	}

	public void setTab5MainPromotion(String tab5MainPromotion) {
		this.tab5MainPromotion = tab5MainPromotion;
	}

	public void setTab5ProdId1(String tab5ProdId1) {
		this.tab5ProdId1 = tab5ProdId1;
	}

	public void setTab5ProdId2(String tab5ProdId2) {
		this.tab5ProdId2 = tab5ProdId2;
	}

	public void setTab5SecondPromotion(String tab5SecondPromotion) {
		this.tab5SecondPromotion = tab5SecondPromotion;
	}

	public void setTab5Title(String tab5Title) {
		this.tab5Title = tab5Title;
	}

	boolean validateFile(File imgFile, String fieldName, String fieldNameMsg, String fileName, double fileSize,
			int fileWidth, int fileHeight) throws IOException {
		int error_size = 0;
		if (null != imgFile) {
			if ((imgFile.length() / 1024) > fileSize) {
				addFieldError(fieldName, fieldNameMsg + "檔案尺寸不符");
				error_size++;
			}
			// flash檔不檢查長寬
			if (!StringUtils.endsWithIgnoreCase(fileName, ".swf")) {
				Image image = ImageIO.read(imgFile);
				if (image.getHeight(null) > fileHeight || image.getWidth(null) > fileWidth) {
					addFieldError(fieldName, fieldNameMsg + "檔案长度/宽度不符");
					error_size++;
				}
			}
			if (error_size > 0) {
				return false;
			} else {
				return true;
			}
		} else {
			return false;
		}
	}

	public String getAdWord() {
		return adWord;
	}

	public void setAdWord(String adWord) {
		this.adWord = adWord;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public boolean isDoClone() {
		return doClone;
	}

	public void setDoClone(boolean doClone) {
		this.doClone = doClone;
	}
}